#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/msg.h>

int main(int argc, char *argv[])
{
    int c, flag, mqid;
    key_t key;
    
    flag = 0600|IPC_CREAT;
    while ((c = getopt(argc, argv, "e")) != -1)
    {
        switch (c) 
        {
            case 'e':
            flag |= IPC_EXCL;
            break;
        }
    }

    if (optind != argc-1)
    {
        printf("usage: %s [-e] [pathname]\n", argv[0]);
        exit(0);
    }

    if ((key = ftok(argv[optind], 0)) < 0)
    {
        perror("ftok error");
        exit(0);
    }

    if ((mqid = msgget(key, flag)) == -1)
    {
        perror("msgget error");
        exit(0);
    }

    printf("mqid is %d\n", mqid);

    return 0;
}
